// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import {emitType} from "./GameData_red_blue_man";
import Music, {musicName} from "../PublicScript/Music";

const {ccclass, property} = cc._decorator;

@ccclass
export default class SkinNode extends cc.Component {

    @property(sp.Skeleton)
    skin: sp.Skeleton[] = [];
    @property(cc.Node)
    lock: cc.Node = null;
    @property(cc.Node)
    bg: cc.Node = null;

    skinNum = 0;
    lockState = false;
    //对应的数据表中的id
    dataNum = 0;

    // onLoad () {}

    start () {

    }

    setSkinNum(name, lockState, dataNum){
        this.skinNum = parseInt(name);
        this.lockState = lockState;
        this.dataNum = dataNum;
        this.changeSkin();
    }

    changeSkin() {
        let name1 = "blue" + this.skinNum;
        let name2 = "red" + this.skinNum;
        this.skin[0].defaultSkin = name2;
        this.skin[1].defaultSkin = name1;
        this.lock.active = this.lockState;
    }


    onClick(){
        Music.GamePlayEffect(musicName.click);
        cc.game.emit(emitType.changeShowSkin, this.skinNum, this.node, this.dataNum);
    }

    changeBgSprite(spr){
        this.bg.getComponent(cc.Sprite).spriteFrame = spr;
    }

    // update (dt) {}
}
